home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / XformX.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-01  |  8.9 KB  |  242 lines

  1. /*
  2.  * (c) Copyright 1995, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  * Permission to use, copy, modify, and distribute this software for
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  *
  25.  * US Government Users Restricted Rights
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * Author: John Spitzer, SGI Applied Engineering
  36.  *
  37.  */
  38.  
  39. /* Define calls if using function pointers or not */
  40. #ifdef FUNCTION_PTRS
  41.   #if (TRANSFORM_TYPE == Translate)
  42.    #ifdef WIN32
  43.     #define DEFINE_TRANSFORM void (APIENTRY *translate)(GLfloat, GLfloat, GLfloat) = glTranslatef;
  44.    #else
  45.     #define DEFINE_TRANSFORM void (*translate)(GLfloat, GLfloat, GLfloat) = glTranslatef;
  46.    #endif
  47.     #define TRANSFORM_CALL (*translate)(ptr[0], ptr[1], ptr[2]); ptr+=3;
  48.   #elif (TRANSFORM_TYPE == Rotate)
  49.    #ifdef WIN32
  50.     #define DEFINE_TRANSFORM void (APIENTRY *rotate)(GLfloat, GLfloat, GLfloat, GLfloat) = glRotatef;
  51.    #else
  52.     #define DEFINE_TRANSFORM void (*rotate)(GLfloat, GLfloat, GLfloat, GLfloat) = glRotatef;
  53.    #endif
  54.     #define TRANSFORM_CALL (*rotate)(ptr[0], ptr[1], ptr[2], ptr[3]); ptr+=4;
  55.   #elif (TRANSFORM_TYPE == Scale)
  56.    #ifdef WIN32
  57.     #define DEFINE_TRANSFORM void (APIENTRY *scale)(GLfloat, GLfloat, GLfloat) = glScalef;
  58.    #else
  59.     #define DEFINE_TRANSFORM void (*scale)(GLfloat, GLfloat, GLfloat) = glScalef;
  60.    #endif
  61.     #define TRANSFORM_CALL (*scale)(ptr[0], ptr[1], ptr[2]); ptr+=3;
  62.   #elif (TRANSFORM_TYPE == Perspective)
  63.    #ifdef WIN32
  64.     #define DEFINE_TRANSFORM void (APIENTRY *perspective)(GLdouble, GLdouble, GLdouble, GLdouble) = gluPerspective;
  65.    #else
  66.     #define DEFINE_TRANSFORM void (*perspective)(GLdouble, GLdouble, GLdouble, GLdouble) = gluPerspective;
  67.    #endif
  68.     #define TRANSFORM_CALL (*perspective)(ptr[0], ptr[1], ptr[2], ptr[3]); ptr+=4;
  69.   #elif (TRANSFORM_TYPE == Ortho)
  70.    #ifdef WIN32
  71.     #define DEFINE_TRANSFORM void (APIENTRY *ortho)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble) = glOrtho;
  72.    #else
  73.     #define DEFINE_TRANSFORM void (*ortho)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble) = glOrtho;
  74.    #endif
  75.     #define TRANSFORM_CALL (*ortho)(ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]); ptr+=6;
  76.   #elif (TRANSFORM_TYPE == Ortho2)
  77.    #ifdef WIN32
  78.     #define DEFINE_TRANSFORM void (APIENTRY *ortho2)(GLdouble, GLdouble, GLdouble, GLdouble) = gluOrtho2D;
  79.    #else
  80.     #define DEFINE_TRANSFORM void (*ortho2)(GLdouble, GLdouble, GLdouble, GLdouble) = gluOrtho2D;
  81.    #endif
  82.     #define TRANSFORM_CALL (*ortho2)(ptr[0], ptr[1], ptr[2], ptr[3]); ptr+=4;
  83.   #elif (TRANSFORM_TYPE == Frustum)
  84.    #ifdef WIN32
  85.     #define DEFINE_TRANSFORM void (APIENTRY *frustum)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble) = glFrustum;
  86.    #else
  87.     #define DEFINE_TRANSFORM void (*frustum)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble) = glFrustum;
  88.    #endif
  89.     #define TRANSFORM_CALL (*frustum)(ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]); ptr+=6;
  90.   #endif
  91.   #ifdef POINT_DRAW
  92.     #define VERTEX_CALL  (*vertex3fv)(point);
  93.     #define BEGIN_CALL   (*begin)(GL_POINTS);
  94.     #define END_CALL     (*end)();
  95.   #endif
  96.   #ifdef PUSH_POP
  97.     #define PUSH_CALL  (*pushmatrix)();
  98.     #define POP_CALL   (*popmatrix)();
  99.   #endif
  100. #else
  101.   #if (TRANSFORM_TYPE == Translate)
  102.     #define TRANSFORM_CALL glTranslatef(ptr[0], ptr[1], ptr[2]); ptr+=3;
  103.   #elif (TRANSFORM_TYPE == Rotate)
  104.     #define TRANSFORM_CALL glRotatef(ptr[0], ptr[1], ptr[2], ptr[3]); ptr+=4;
  105.   #elif (TRANSFORM_TYPE == Scale)
  106.     #define TRANSFORM_CALL glScalef(ptr[0], ptr[1], ptr[2]); ptr+=3;
  107.   #elif (TRANSFORM_TYPE == Perspective)
  108.     #define TRANSFORM_CALL gluPerspective(ptr[0], ptr[1], ptr[2], ptr[3]); ptr+=4;
  109.   #elif (TRANSFORM_TYPE == Ortho)
  110.     #define TRANSFORM_CALL glOrtho(ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]); ptr+=6;
  111.   #elif (TRANSFORM_TYPE == Ortho2)
  112.     #define TRANSFORM_CALL gluOrtho2D(ptr[0], ptr[1], ptr[2], ptr[3]); ptr+=4;
  113.   #elif (TRANSFORM_TYPE == Frustum)
  114.     #define TRANSFORM_CALL glFrustum(ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]); ptr+=6;
  115.   #endif
  116.   #ifdef POINT_DRAW
  117.     #define VERTEX_CALL  glVertex3fv(point);
  118.     #define BEGIN_CALL   glBegin(GL_POINTS);
  119.     #define END_CALL     glEnd();
  120.   #endif
  121.   #ifdef PUSH_POP
  122.     #define PUSH_CALL  glPushMatrix();
  123.     #define POP_CALL   glPopMatrix();
  124.   #endif
  125. #endif
  126.  
  127. #ifdef POINT_DRAW
  128.   #define DEFINE_POINT GLfloat point[3] = { 0.0, 0.0, -1.0 };
  129.   #define PRE_TRANSFORM  \
  130.     TRANSFORM_CALL \
  131.     BEGIN_CALL   \
  132.     VERTEX_CALL  \
  133.     END_CALL
  134. #else
  135.   #define DEFINE_POINT
  136.   #define PRE_TRANSFORM  \
  137.     TRANSFORM_CALL
  138. #endif
  139.  
  140. #ifdef PUSH_POP
  141.   #define TRANSFORM \
  142.     PUSH_CALL       \
  143.     PRE_TRANSFORM   \
  144.     POP_CALL
  145. #else
  146.   #define TRANSFORM \
  147.     PRE_TRANSFORM
  148. #endif
  149.   
  150. /* Unroll the transforms to the number specified */
  151. #if (UNROLL == 1)
  152.   #define UNROLLED_TRANSFORMS TRANSFORM
  153.   #define DEFINE_CLEANUP
  154. #elif (UNROLL == 2)
  155.   #define UNROLLED_TRANSFORMS TRANSFORM TRANSFORM
  156.   #define DEFINE_CLEANUP int remainingTransforms = iterations & 1;
  157. #elif (UNROLL == 3)
  158.   #define UNROLLED_TRANSFORMS TRANSFORM TRANSFORM TRANSFORM
  159.   #define DEFINE_CLEANUP int remainingTransforms = iterations % 3;
  160. #elif (UNROLL == 4)
  161.   #define UNROLLED_TRANSFORMS TRANSFORM TRANSFORM TRANSFORM TRANSFORM
  162.   #define DEFINE_CLEANUP int remainingTransforms = iterations & 3;
  163. #elif (UNROLL == 5)
  164.   #define UNROLLED_TRANSFORMS TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM
  165.   #define DEFINE_CLEANUP int remainingTransforms = iterations % 5;
  166. #elif (UNROLL == 6)
  167.   #define UNROLLED_TRANSFORMS TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM
  168.   #define DEFINE_CLEANUP int remainingTransforms = iterations % 6;
  169. #elif (UNROLL == 7)
  170.   #define UNROLLED_TRANSFORMS TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM
  171.   #define DEFINE_CLEANUP int remainingTransforms = iterations % 7;
  172. #elif (UNROLL == 8)
  173.   #define UNROLLED_TRANSFORMS TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM
  174.   #define DEFINE_CLEANUP int remainingTransforms = iterations & 7;
  175. #endif
  176.  
  177. #if (UNROLL > 1)
  178.   #define CLEANUP_LOOP \
  179.     ptr = data; \
  180.     for (i=remainingTransforms; i>0; i--) { \
  181.       TRANSFORM \
  182.     }
  183. #else
  184.   #define CLEANUP_LOOP
  185. #endif
  186.  
  187. void FUNCTION (TestPtr thisTest)
  188. {
  189.     TransformPtr this = (TransformPtr)thisTest;
  190.     int iterations = this->iterations;
  191.     int loops = iterations/UNROLL;
  192.     int i;
  193.     DEFINE_POINT
  194.     DEFINE_CLEANUP
  195.     GLfloat *data = this->transformData;
  196.     GLfloat *ptr;
  197.   #ifdef FUNCTION_PTRS
  198.    #ifdef WIN32
  199.     #ifdef POINT_DRAW
  200.       void (APIENTRY *vertex3fv)(const GLfloat*) = glVertex3fv;
  201.       void (APIENTRY *begin)(GLenum) = glBegin;
  202.       void (APIENTRY *end)(void) = glEnd;
  203.     #endif
  204.     #ifdef PUSH_POP
  205.       void (APIENTRY *pushmatrix)(void) = glPushMatrix;
  206.       void (APIENTRY *popmatrix)(void) = glPopMatrix;
  207.     #endif
  208.    #else
  209.     #ifdef POINT_DRAW
  210.       void (*vertex3fv)(const GLfloat*) = glVertex3fv;
  211.       void (*begin)(GLenum) = glBegin;
  212.       void (*end)(void) = glEnd;
  213.     #endif
  214.     #ifdef PUSH_POP
  215.       void (*pushmatrix)(void) = glPushMatrix;
  216.       void (*popmatrix)(void) = glPopMatrix;
  217.     #endif
  218.    #endif
  219.     DEFINE_TRANSFORM
  220.   #endif
  221.  
  222.     for (i=loops; i>0; i--) {
  223.         ptr = data;
  224.         UNROLLED_TRANSFORMS
  225.     }
  226.     CLEANUP_LOOP
  227. }
  228.  
  229. #undef TRANSFORM_CALL
  230. #undef BEGIN_CALL
  231. #undef END_CALL
  232. #undef VERTEX_CALL
  233. #undef PUSH_CALL
  234. #undef POP_CALL
  235. #undef PRE_TRANSFORM
  236. #undef TRANSFORM
  237. #undef UNROLLED_TRANSFORMS
  238. #undef DEFINE_TRANSFORM
  239. #undef DEFINE_POINT
  240. #undef DEFINE_CLEANUP
  241. #undef CLEANUP_LOOP
  242.